package com.techfengs.chapter03;

public class ForceConvertDetail {
  public static void main (String[] args) {
    // 强制类型转换
    // int x = (int)10*3.5+6*1.5;
    // 编译×
    int x = (int)(10*3.5+6*1.5);
    System.out.println(x);

    char c1 = 100;
    int m = 100;
    // char c2 = m;
    char c3 = (char)m;
    // 100对应的字符
    System.out.println(c3);

    // short s = 12;
    // s = s-9;
    // System.out.println(s);
    // ×，等号右侧运算后是int类型
    byte b = 10;
    // b = b+10;
    // System.out.println(b);
    // ×，等号右侧运算后是int类型
    b = (byte)(b+11);
    System.out.println(b);
    // √，等号右侧运算后是int类型，强制转换成byte类型后与左侧一致
    char c = 'a';
    int i = 16;
    float d = .314F;
    double result = c+i+d;
    System.out.println(result);
    // √，等号右侧运算后自动转换为精度最高的float类型，赋值后再次自动转换为double类型
    // byte b2 = 16;
    // short s2 = 14;
    // short t = s2+b2;
    // // ×，等号右侧参与运算之前自动转换为int类型
  }
}
